package com.bjgzy.rating.di.module;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bjgzy.rating.R;
import com.bjgzy.rating.mvp.contract.RatingHomeContract;
import com.bjgzy.rating.mvp.model.RatingHomeModel;
import com.blankj.utilcode.util.TimeUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.entity.RatingHomeData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.jess.arms.di.scope.ActivityScope;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-8-7 15:54:08
 */
@Module
public abstract class RatingHomeModule {

    @Binds
    abstract RatingHomeContract.Model bindRatingHomeModel(RatingHomeModel model);

    @ActivityScope
    @Provides
    static List<RatingHomeData> provideList() {
        return new ArrayList<>();
    }

    @ActivityScope
    @Provides
    static BaseQuickAdapter<RatingHomeData, AutoBaseViewHolder> provideActivityAdapter(List<RatingHomeData> list) {
        return new BaseQuickAdapter<RatingHomeData, AutoBaseViewHolder>(R.layout.rating_rv_item_home, list) {
            @Override
            protected void convert(AutoBaseViewHolder helper, RatingHomeData item) {
                Glide.with(helper.itemView.getContext())
                        .load(item.getImgUrl())
                        .apply(RequestOptions.placeholderOf(R.drawable.public_img_default).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                        .into((ImageView) helper.getView(R.id.iv_logo));
                TextView status = helper.getView(R.id.tv_status);
                //0未开始  1作品上传    2大众投票   3专家评审  4活动结束  5结果公布   6已结束
                status.setText(item.getStatusStr());
                if (item.getStatus() == 0 || item.getStatus() == 6 || item.getStatus() == 4) {
                    status.setSelected(false);
                } else {
                    status.setSelected(true);
                }
                String startDate = TimeUtils.millis2String(item.getStartDate(), new SimpleDateFormat("yyyy.MM.dd"));
                String endDate = TimeUtils.millis2String(item.getEndDate(), new SimpleDateFormat("yyyy.MM.dd"));
                helper.setText(R.id.tv_time, startDate + "-" + endDate);
            }

        };
    }

    @ActivityScope
    @Provides
    static RecyclerView.LayoutManager provideLayoutManger(RatingHomeContract.View view) {
        return new LinearLayoutManager(view.getActivity());
    }
}